<div id="wapper">
  <div id="content">
    <?php $this->load->view("layouts/left"); ?>
    <div id="contentm">
      <div class="homelink">&spades; <a href="<?php echo base_url(); ?>">Trang chủ</a> &raquo; <a href="<?php echo $category['rewrite']; ?>.html" title="<?php echo $category['names']; ?>"><?php echo $category['names']; ?></a> &raquo; <a href="<?php echo $links; ?>" title="<?php echo $result['title']; ?>"><?php echo $result['title']; ?></a></div>
      <div class="dquestion">
        	<div class="quesuser">
                <?php if($result['image'] == NULL){ ?>
            	<img src="<?php echo base_url(); ?>public/images/no-avatar.png" width="90" height="90" alt="<?php echo $result['username'] ?>" title="<?php echo $result['username'] ?>" />
                <?php }else{ ?>
                <img src="<?php echo base_url(); ?>uploads/users/thumb/<?php echo $result['image']; ?>" width="90" height="90" alt="<?php echo $result['username'] ?>" title="<?php echo $result['username'] ?>" />
                <?php } ?>
            </div>
            <div class="quesinfo">
            	<h1><?php echo $result['title']; ?></h1>
                <p class="qinfo">Gửi bởi <a href="#"><?php echo $result['username']; ?></a> lúc <?php echo $result['datetime']; ?></p>
            	<div class="quesinfocon"><?php echo $result['info']; ?></div>
            </div>
            <div class="cls"></div>
        </div>
        <div class="totalansw">
        	<h3>Có <?php if(isset($listanswer)){ echo count($listanswer);}else{ echo 0;} ?> câu trả lời</h3>
        </div>
        <script type="text/javascript">
			$(document).ready(function(e){
				$(".fdel").live("click",function(){
					$id = $(this).attr("title");
					$type = $(this).attr("name");
					if(confirm('Bạn có chắc không?')) {
	  					$(this).parent().parent().fadeOut();
	  					jQuery.post("<?php echo base_url()."home/answers/manaasw"; ?>",{id:$id,type:$type},function(result){
							if(result == "edit"){
								window.location = "<?php echo base_url()."sua-cau-tra-loi.html?quesid="; ?>"+$id+"&url=<?php echo $links; ?>";
							}
	  					});
					}else{ return false; }
				});
				$(".vtclick").live("click",function(){
					$val = $(this).text();
					$total = parseFloat($val) + 1;
					$aswid = $(this).attr("dataid");
					$type = $(this).attr("name");
					$(this).html($total);
					$(this).addClass("upactive");
					jQuery.post("<?php echo base_url()."home/answers/votenow"; ?>",{val:$val,type:$type,aswid:$aswid},function(result){
						if(result == 1){
							window.location = "<?php echo base_url(); ?>dang-nhap.html";
						}else{
							alert("true");
						}
					});
				});
			});
		</script>
        <div class="listanswer" id="listanswer">
        <?php if(isset($listanswer)){ ?>
        <?php foreach($listanswer as $answers){ ?>
        	<div class="answers">
            	<div class="lanswerl">
                	<?php if($answers['image'] == NULL){ ?>
                    <img src="<?php echo base_url(); ?>public/images/no-avatar.png" width="50" alt="<?php echo $answers['username']; ?>" title="<?php echo $answers['username']; ?>" />
                    <?php }else{ ?>
                    <img src="<?php echo base_url(); ?>uploads/users/thumb/<?php echo $answers['image']; ?>" width="50" alt="<?php echo $answers['username']; ?>" title="<?php echo $answers['username']; ?>" />
                    <?php } ?>
                    <p style="padding:3px 0px"><a href="#"><?php echo $answers['username']; ?></a></p>
	            </div>
	            <div class="lanswerr">
                	<?php if(isset($this->session->userdata['userlevel']) && $this->session->userdata['userlevel'] == 1){ ?>
                	<a href="javascript:void(0)" rel="nofollow" name="hide" class="fdel" title="<?php echo $answers['aid']; ?>">Ẩn</a>
                	<a href="javascript:void(0)" rel="nofollow" name="del" class="fdel" title="<?php echo $answers['aid']; ?>">Xóa</a>
                    <a href="javascript:void(0)" rel="nofollow" name="edit" class="fdel" title="<?php echo $answers['aid']; ?>">Sửa</a>
                    <?php } ?>
	            	<div class="answercon">
	                	<?php echo $answers['ainfo']; ?>
	                </div>
	            	<div class="answertool">
                    	<div class="ansup">
                        	<a href="javascript:void(0)" name="voteup" dataid="<?php echo $answers['aid']; ?>" class="voteup vtclick"><?php echo $answers['alike']; ?></a>
                        </div>
                        <div class="ansdown">
                        	<a href="javascript:void(0)" name="votedown" dataid="<?php echo $answers['aid']; ?>" class="votedown vtclick"><?php echo $answers['adislike']; ?></a>
                        </div>
                        <div class="ansnow">
                            <a href="javascript:void(0)" class="commnow">Trả lời</a>
                        </div>
	                </div>
	            </div>
	            <div class="cls"></div>
            </div>
        <?php } } ?>
        </div>
        <script type="text/javascript">
			$(document).ready(function(e){
				$("#fanswer").focus(function(){
					//$(this).css("height","140px");
				});
                $("#fsubmit").click(function(){
					$userid = $("#fuserid").val();
					$fusername = $("#fusername").val();
					$quesid = $("#fquestid").val();
					$cateid = $("#fcateid").val();
					$value  = $("#fanswer").val();
					$errors = $("#ferrors");$result = $("#listanswer");
					if($userid == ""){
						window.location = "<?php echo base_url()."dang-nhap.html?url=".$links; ?>";
					}else{
						if($value == ""){
							$errors.text("Bạn chưa nhập câu trả lời").show();
						}else{
							if($value.length < 10){
								$errors.text("Câu trả lời quá ngắn!").show();
							}else{
								$errors.removeAttr("id").html("<img src='<?php echo base_url(); ?>public/images/4-0.gif' alt='' /> loading...");
								jQuery.post("<?php echo base_url()."home/question/asnwers"; ?>",{userid:$userid,fusername:$fusername,quesid:$quesid,cateid:$cateid,value:$value},function(result){
									$errors.html("").hide();
									$result.html(result);
									$("#fanswer").val("").css("height","57px");
								});
							}
						}
					}
					return false;
				});
            });
        </script>
        <div class="fanswer">
        <?php if(isset($this->session->userdata['userid'])){ ?>
        	<?php $this->load->view("layouts/form-answer-login"); ?>
        </div>
        <?php }else{ ?>
        	<p id="ferrors" style="display:block">Bạn chưa <a href="<?php echo base_url()."dang-nhap.html?url=".$links; ?>" style="color:#060">đăng nhập</a>, bạn không thể trả lời câu hỏi này</p>
        	<form action="" method="post">
      		<div class="fanserl">
            	<img src="<?php echo base_url(); ?>public/images/no-avatar.png" width="50" />
            </div>
            <div class="fanserm">
                <textarea name="answer" id="fanswer" cols="50" rows="4" placeholder="Đăng nhập để trả lời!" disabled="disabled"></textarea>
            </div>
            <div class="fanserr">
            	<input type="submit" name="submit" id="fsubmit" value="Trả lời" disabled="disabled" />
            </div>
            </form>
        <?php } ?>
      </div>
    </div>
    <?php $this->load->view("layouts/right"); ?>
      <div class="cls"></div>
  </div>
</div>
